import router from './router/index'
import {
    store
} from './store'
import Cookies from "js-cookie"
import axios from "axios";
//检验token是否存在
function getToken() {
    var token = "";
    token = store.getters.token;
    if (token) {
        return token;
    }
    token = Cookies.get('token');
    if (token) {
        return token;
    } else {
        return "";
    }
}
function getUserInfo() {
    axios
        .get(
            "/api/salary/user/getUserInfo"
        )
        .then(response => {
            var httpStatus = response.data.status;
            if (httpStatus === 200) {
                store.commit("setUserInfo", response.data.data);
            }
        });
}
router.beforeEach((to, from, next) => {
    if (to.path != '/Login' && to.path != '/sso') {
        var token = getToken();
        if (!token) { //如果尚未登录，跳转到登录界面
            return next('/Login');
        } else {
        }

    }
    next();
});